# this requires the RCOV gem to be installed on your system
namespace :test do
  desc "Generate code coverage with rcov"
  task :coverage do
    DEST_DIR = 'doc/coverage'
    COVERAGE = "#{DEST_DIR}/coverage.data"
    
    rm_f COVERAGE if File.exists? COVERAGE
    mkdir DEST_DIR if !File.exists? DEST_DIR
    rcov = %(rcov --rails --aggregate #{COVERAGE} --text-summary -Ilib --html -o #{DEST_DIR} test/**/*_test.rb)
    system rcov
    system "open #{DEST_DIR}/index.html" if PLATFORM['darwin']
    system "firefox #{DEST_DIR}/index.html" if (PLATFORM.include?('linux') && has_firefox?)
  end
  
  def has_firefox?
    return system("which firefox")
  end
end